package cn.datawin.dockerclient.service.impl;

import cn.datawin.bms.deploy.entity.DeplServerModuleInfoEntity;
import cn.datawin.dockerclient.mapper.DeplServerModuleInfoMapper;
import cn.datawin.dockerclient.service.DeplModuleInfoService;
import cn.datawin.dockerclient.service.DeplServerModuleInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 服务器端口信息表
 *
 * @author shengdongcloud
 * @date 2025-03-13 13:55:38
 */
@RequiredArgsConstructor
@Service
public class DeplServerModuleInfoServiceImpl extends ServiceImpl<DeplServerModuleInfoMapper, DeplServerModuleInfoEntity> implements DeplServerModuleInfoService {

	/**
	 * 更新服务器模块信息
	 * @param moduleId 模块id
	 * @param serverIp 服务器ip
	 * @param serverPort 服务器port
	 * @param status 状态 0 空闲 1 占用
	 */
	@Override
	public void updateServerModuleInfo(int moduleId, String serverIp, String serverPort, int status) {
		//根据moduleId、serverIp和serverPort 更新status
		LambdaQueryWrapper <DeplServerModuleInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(DeplServerModuleInfoEntity::getModuleId, moduleId);
		queryWrapper.eq(DeplServerModuleInfoEntity::getServerIp, serverIp);
		queryWrapper.eq(DeplServerModuleInfoEntity::getServerPort, serverPort);
		DeplServerModuleInfoEntity entity = new DeplServerModuleInfoEntity();
		entity.setStatus(status);
		entity.setUpdatetime(LocalDateTime.now());
		this.baseMapper.update(entity, queryWrapper);
	}
}
